home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993…ch: Other People's Memory / ADC Developer CD (1993-03) (''Other People's Memory'')_iso / Dev.CD Mar 93.iso / Technical Documentation / Sample Code / DTS.Lib & Samples / DTS.Lib / DTS.Lib.headers / TreeObj.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-22  |  12.7 KB  |  393 lines  |  [TEXT/MPS ]

  1. #ifndef __TREEOBJ__
  2. #define __TREEOBJ__
  3.  
  4. #ifndef __TYPES__
  5. #include <Types.h>
  6. #endif
  7.  
  8. #ifndef __ERRORS__
  9. #include <Errors.h>
  10. #endif
  11.  
  12. #ifndef __EVENTS__
  13. #include <Events.h>
  14. #endif
  15.  
  16. #ifndef __MEMORY__
  17. #include <Memory.h>
  18. #endif
  19.  
  20. #define NO_EDIT 0                        /* System edit type. */
  21.  
  22.  
  23. /********/
  24.  
  25.  
  26. #define EMPTYOBJ    0
  27. #define ROOTOBJ     1
  28. #define UNDOOBJ     2
  29. #define UNDOTASKOBJ 3
  30. #define UNDOPARTOBJ 4
  31.  
  32. struct FileRec;
  33. typedef struct FileRec *FileRecPtr, **FileRecHndl;
  34.  
  35. struct TreeObj;
  36. typedef struct TreeObj *TreeObjPtr, **TreeObjHndl;
  37. typedef long    (*TreeObjProcPtr)(TreeObjHndl hndl, short message, long data);
  38.  
  39. typedef struct TreeObj {
  40.     short        type;
  41.     short        numChildren;
  42.     long        dataSize;
  43.     long        treeID;
  44.     TreeObjHndl    parent;
  45. } TreeObj;
  46.  
  47. long    TUndoObj(TreeObjHndl hndl, short message, long data);
  48. typedef struct {
  49.     TreeObjHndl    root;
  50.     FileRecHndl    frHndl;
  51.     Boolean        disabled;
  52.     short        lastEditType;
  53.     short        undoDepth;
  54.     short        maxNumUndos;
  55.     short        numSaveUndos;
  56. } UndoObj;
  57.  
  58. long    TUndoTaskObj(TreeObjHndl hndl, short message, long data);
  59. typedef struct {
  60.     short    editType;
  61.     Point    undoOrigin;
  62.     Point    redoOrigin;
  63. } UndoTaskObj;
  64.  
  65. long    TUndoPartObj(TreeObjHndl hndl, short message, long data);
  66. typedef struct {
  67.     short        actionType;
  68.     TreeObjHndl    shndl;
  69.     short        scnum;
  70.     TreeObjHndl    dhndl;
  71.     short        dcnum;
  72.     Boolean        deepCopy;
  73. } UndoPartObj;
  74.  
  75. struct VHFormatData {
  76.     Handle    text;
  77.     char    *header;
  78.     char    *data;
  79. };
  80. typedef struct VHFormatData VHFormatData;
  81. typedef VHFormatData *VHFormatDataPtr;
  82.  
  83. #define mDerefUndo(hndl)     ((UndoObj*)(((char*)(*(hndl)))+sizeof(TreeObj)))
  84. #define mDerefUndoTask(hndl) ((UndoTaskObj*)(((char*)(*(hndl)))+sizeof(TreeObj)))
  85. #define mDerefUndoPart(hndl) ((UndoPartObj*)(((char*)(*(hndl)))+sizeof(TreeObj)))
  86.  
  87.  
  88. /********/
  89.  
  90.  
  91. #define INITMESSAGE      0        /* Additional object initialization. */
  92. #define     CREATEINIT       0        /* Object being initially created. */
  93. #define     WINDOWINIT       1        /* Document/object being assigned to a window. */
  94. #define     NOWINDOWINIT     2        /* Document/object being freed from a window. */
  95.  
  96. #define FREEMESSAGE      1        /* Additional object disposal. */
  97.  
  98. #define COPYMESSAGE      2        /* Additional object cloning. */
  99.  
  100. #define UNDOMESSAGE      3        /* Additional object undo. */
  101. #define     UNDOFROMDOC      0        /* Object leaving document. */
  102. #define     UNDOTODOC        1        /* Object returning to document. */
  103.  
  104. #define CONVERTMESSAGE   4        /* Hndl2ID or ID2Hndl conversions. */
  105. #define     CONVERTTOID      0        /* Convert handle references to ID references. */
  106. #define     CONVERTTOHNDL    1        /* Convert ID references to handle references. */
  107.  
  108. #define FREADMESSAGE     5        /* Read object data from file. */
  109. #define FWRITEMESSAGE    6        /* Write object data to file. */
  110.  
  111. #define HREADMESSAGE     7        /* Read object data from handle. */
  112. #define HWRITEMESSAGE    8        /* Write object data to handle. */
  113.  
  114. #define HITTESTMESSAGE   9        /* Test if object was hit. */
  115. #define     HITTESTOBJ       0        /* Test body of object for hit. */
  116. #define     HITTESTGRABBER   1        /* Test sizing parts for hit. */
  117. #define     CANBETARGET      2        /* Return true if object can become target. */
  118. #define     CANTAKEKEYS      3        /* Return true if target can take keys. */
  119.  
  120. #define GETRGNMESSAGE    10        /* Return object bounding box. */
  121. #define GETBBOXMESSAGE   11        /* Return object bounding box. */
  122. #define SETBBOXMESSAGE   12        /* Set object bounding box. */
  123. #define SECTBBOXMESSAGE  13        /* Check if rect intersects object bounding box. */
  124.  
  125. #define TARGETMESSAGE    14        /* Set target status for object. */
  126. #define     TARGETOFF        0        /* Make the object no longer the target. */
  127. #define     TARGETON         1        /* Make the object the target. */
  128.  
  129. #define DRAWMESSAGE      15        /* Draw some form of the object. */
  130. #define     DRAWOBJ          0        /* Draw the object. */
  131. #define     ERASEOBJ         1        /* Draw the object. */
  132. #define     DRAWSELECT       2        /* Draw the selection portion of the object. */
  133. #define     DRAWGHOST        3        /* Draw an xor-ghost (for dragging) of the image. */
  134. #define     DRAWMASK         4        /* Draw a mask of the image (for offscreen layer masking.) */
  135.  
  136. #define PRINTMESSAGE     16
  137.  
  138. #define VHMESSAGE        17        /* Format View Hierarchy information for the objet. */
  139.  
  140.  
  141.  
  142. #define DOUNDO 0
  143. #define DOREDO 1
  144.  
  145.  
  146.  
  147. TreeObjHndl    NewRootObj(short ctype, long size);
  148.     /* Creates an object with no parent.  This object will be the root object
  149.     ** for a tree.  Returns nil upon failure. */
  150.  
  151.  
  152.  
  153. TreeObjHndl    NewChild(short editType, TreeObjHndl parentHndl, short childNum, short ctype, long size);
  154.     /* Creates a child of the specified type and adds it to the parent at the
  155.     ** specified location.  Returns nil upon failure. */
  156.  
  157.  
  158.  
  159. void        DisposeChild(short editType, TreeObjHndl parentHndl, short childNum);
  160.     /* Disposes of the specified child and all offspring of that child. */
  161.  
  162.  
  163.  
  164. TreeObjHndl    CopyChild(short editType, TreeObjHndl shndl, short scnum, TreeObjHndl dhndl, short dcnum, Boolean deepCopy);
  165.     /* Copies the specified child (and all offspring of that child if deepCopy is true). */
  166.  
  167.  
  168.  
  169. OSErr        MoveChild(short editType, TreeObjHndl shndl, short scnum, TreeObjHndl dhndl, short dcnum);
  170.     /* Moves a child from one location on the tree to another. */
  171.  
  172.  
  173.  
  174. OSErr        ModifyChild(short editType, TreeObjHndl phndl, short cnum, Boolean deepCopy);
  175.     /* Saves a copy of the child in the undo hierarchy for undo/redo purposes. */
  176.  
  177.  
  178.  
  179. OSErr        SwapChildren(short editType, TreeObjHndl hndla, short cnuma, TreeObjHndl hndlb, short cnumb);
  180.     /* Swaps the child handles. */
  181.  
  182.  
  183.  
  184. OSErr        SwapChildData(TreeObjHndl hndla, TreeObjHndl hndlb);
  185.     /* Swaps the child data without swapping the handles. */
  186.  
  187.  
  188.  
  189. void        DisposeObjAndOffspring(TreeObjHndl childHndl);
  190.     /* This disposes of the child and any offspring of that child.  It does not remove
  191.     ** the child from the parent's child handle table. */
  192.  
  193.  
  194.  
  195. OSErr        CopyChildren(TreeObjHndl shndl, TreeObjHndl dhndl);
  196.     /* Copies the children (and children below that and so on) of one object to
  197.     ** another object.  Used internally by CopyChild for deep copies. */
  198.  
  199.  
  200.  
  201. OSErr        InsertChildHndl(TreeObjHndl parentHndl, TreeObjHndl childHndl, short childNum);
  202.     /* Adds an existing child to a parent's child handle table. */
  203.  
  204.  
  205.  
  206. void        DeleteChildHndl(TreeObjHndl parentHndl, short childNum);
  207.     /* Removes a child from the parent's child handle table. */
  208.  
  209.  
  210.  
  211. TreeObjHndl    GetRootHndl(TreeObjHndl hndl);
  212.     /* Given an object handle, return the root handle. */
  213.  
  214.  
  215.  
  216. TreeObjHndl    GetChildHndl(TreeObjHndl parentHndl, short cnum);
  217.     /* Given a parent handle and a child number, this returns the child handle. */
  218.  
  219.  
  220.  
  221. TreeObjHndl    *GetChildHndlPtr(TreeObjHndl parentHndl, short *childNum, short endCase);
  222.     /* Return a pointer into the child handle table.  This also validates (and corrects)
  223.     ** cnum so that it is in range, if possible.  Depending on the usage, pointing to
  224.     ** just after the child handle table is either valid or invalid.  If a handle is
  225.     ** being added to the table, then pointing just after the table is valid.  If a
  226.     ** handle is being removed or referenced, then pointing just after the table is
  227.     ** invalid.  the parameter endCase determines which case we are dealing with.  If
  228.     ** endCase is 0, then pointing just after the child handle table is invalid, and
  229.     ** if the cnum value passed in causes this, then nil is returned for the pointer.
  230.     ** if endCase is 1, then pointing just after the child handle table is okay, and
  231.     ** therefore nil will never be returned as the pointer.  Any cnum value out of
  232.     ** range will be corrected (if possible) to be within range. */
  233.  
  234.  
  235.  
  236. short        GetChildNum(TreeObjHndl hndl);
  237.     /* Given a child handle, this returns the child number of that
  238.     ** handle in the parent's child handle table. */
  239.  
  240.  
  241.  
  242. OSErr        AdjustDataSize(TreeObjHndl hndl, long delta);
  243.     /* Adjusts the data size, either greater or smaller, depending on the sign of 'delta'. */
  244.  
  245.  
  246.  
  247. OSErr        SetDataSize(TreeObjHndl hndl, long newSize);
  248.     /* Sets the data size to newSize. */
  249.  
  250.  
  251.  
  252. OSErr        SlideData(TreeObjHndl hndl, long offset, long delta);
  253.     /* Slides some of the data in the data portion of the object starting at
  254.     ** 'offset' by a 'delta' amount, either forward or backward, depending
  255.     ** on the sign of 'delta'. */
  256.  
  257.  
  258.  
  259. void        *GetDataPtr(TreeObjHndl hndl);
  260.     /* Returns a pointer to the beginning of the object's data area.
  261.     ** THIS DOES NOT LOCK THE HANDLE!!  The pointer may become invalid
  262.     ** if memory moves. */
  263.  
  264.  
  265.  
  266. OSErr        ReadTree(TreeObjHndl hndl, short fileRefNum);
  267.     /* Given an open file that has been previously written via WriteTree, this function
  268.     ** is called to read the file data into ram.  The root object for the file is already
  269.     ** created by InitDocument.  The file must be open, and the file position must be
  270.     ** set to the byte location where the root object of the file starts.  Once this is
  271.     ** so, just call this function with a reference to the root object and the open file
  272.     ** refrence number. */
  273.  
  274.  
  275.  
  276. OSErr        ReadTreeObjData(TreeObjHndl hndl, short fileRefNum);
  277.     /* Read in dataSize number of bytes into the object. */
  278.  
  279.  
  280.  
  281. OSErr        WriteTree(TreeObjHndl hndl, short fileRefNum);
  282.     /* Given an open file that is ready to be written to, this function is called to
  283.     ** write the file tree to the designated file. */
  284.  
  285.  
  286.  
  287. OSErr        WriteTreeObjData(TreeObjHndl hndl, short fileRefNum);
  288.     /* Write out dataSize number of bytes from the object. */
  289.  
  290.  
  291.  
  292. void        DoBTreeMethod(TreeObjHndl hndl, short message, long data);
  293.     /* Call the object for each member of the tree (or branch) starting
  294.     ** from the back of the tree working forward. */
  295.  
  296.  
  297.  
  298. void        DoFTreeMethod(TreeObjHndl hndl, short message, long data);
  299.     /* Call the object for each member of the tree (or branch) starting
  300.     ** from the front of the tree working backward. */
  301.  
  302.  
  303.  
  304. long        DoTreeObjMethod(TreeObjHndl hndl, short message, long data);
  305.     /* If the object has a method procedure, call it.  If no method procedure,
  306.     ** then do nothing. */
  307.  
  308.  
  309.  
  310. void        DoNumberTree(TreeObjHndl hndl);
  311.     /* Number each member in the tree with a unique treeID.  The tree is number
  312.     ** sequentially from front to back.  The first treeID number is 1.  0 is
  313.     ** reserved for Hndl2ID/ID2Hndl conversions where it is possible that the
  314.     ** handle value is nil.  The nil handle will convert to 0, and convert back
  315.     ** to nil. */
  316.  
  317.  
  318.  
  319. void        Hndl2ID(TreeObjHndl *hndl);
  320.     /* This function is used to convert a handle reference into a treeID reference.
  321.     ** A pointer to the handle reference is passed in.  Typical usage will be where
  322.     ** a handle object has a reference to another handle object.  Handle object
  323.     ** references aren't meaningful when saved to disk, and therefore don't persist
  324.     ** in their native form.  These handle references need to be converted into
  325.     ** a treeID reference so that they can be saved.
  326.     ** The tree first needs to be numbered so that the treeID references are unique
  327.     ** and meaningful.  The tree is numbered by first calling DoNumberTree().  It
  328.     ** numbers all the members of the tree hierarchy uniquely and sequentially. */
  329.  
  330.  
  331.  
  332. void        ID2Hndl(TreeObjHndl refHndl, TreeObjHndl *hndl);
  333.     /* Given a tree object ID and a reference object (any member of the tree),
  334.     ** return the cooresponding object handle.  DoNumberTree() must be called
  335.     ** prior to using this function, and after the last change to the tree, as
  336.     ** it generates the object treeID numbers for the entire tree. */
  337.  
  338.  
  339.  
  340. TreeObjHndl    GetUndoHndl(TreeObjHndl hndl);
  341.     /* Given an object handle, return the undo handle. */
  342.  
  343.  
  344.  
  345. void        NewUndo(TreeObjHndl hndl);
  346.     /* Used to close out an old undo task.  Closing out the old task means that
  347.     ** any editing to the document will be recorded into a new undo task.  Use
  348.     ** this to separate two edits of the same edit type that would otherwise
  349.     ** get recorded into the same undo task. */
  350.  
  351.  
  352.  
  353. void        RevertEdit(TreeObjHndl hndl);
  354.     /* If an edit fails, it can be backed out of by calling this.  All edits
  355.     ** that were done will be undone, thus recovering the state of the
  356.     ** document prior to the edit. */
  357.  
  358.  
  359.  
  360. void        DoUndoTask(TreeObjHndl hndl, Boolean redo, Boolean fixup);
  361.     /* Call this to undo or redo editing to the document.  If redo is false,
  362.     ** the it is an undo task.  If fixup is true, then the fixup application's
  363.     ** undo fixup procedure is called before and after the undo operation. */
  364.  
  365.  
  366.  
  367. void        DisableUndo(TreeObjHndl hndl);
  368.     /* Dispose of all undo information and prevent further undo collection.
  369.     ** Calling NewUndo() will re-enable undo collection. */
  370.  
  371.  
  372.  
  373. void        DisposeUndos(TreeObjHndl hndl);
  374.     /* Dispose of all undo information. */
  375.  
  376.  
  377.  
  378. Boolean        PurgeUndo(TreeObjHndl hndl);
  379.     /* Dispose of all undo information except the current undo.  The current undo
  380.     ** may still be active, and it may be needed to back out of an edit operation. */
  381.  
  382.  
  383.  
  384. void        GetUndoInfo(FileRecHndl frHndl, short *undoDepth, short *numUndos);
  385.     /* Return the depth of the undo state, along with the number of undos.  This
  386.     ** is useful to determine if undo and redo operations are possible.  If undoDepth
  387.     ** is non-zero, then undo is possible.  If numUndos is greater than undoDepth,
  388.     ** then redo is possible. */
  389.  
  390.  
  391.  
  392. #endif
  393.